package com.cskaoyan.service;

import com.cskaoyan.bean.MarketCategory;
import com.cskaoyan.bean.MarketCategoryExample;
import com.cskaoyan.bean.catagoryWx.vo.CatalogIndexVo;
import com.cskaoyan.mapper.MarketCategoryMapper;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

@Service

public class CatalogServiceImpl implements CatalogService{
    @Autowired
    MarketCategoryMapper marketCategoryMapper;

    @Override
    public CatalogIndexVo querIndexCategory() {
        CatalogIndexVo catalogIndexVo = new CatalogIndexVo();
        //所有的父分类展示
        MarketCategoryExample marketCategoryExample = new MarketCategoryExample();
        List<MarketCategory> marketCategories = marketCategoryMapper.selectByExample(marketCategoryExample);
        catalogIndexVo.setCategoryList(marketCategories);

        //默认的父分类
        MarketCategory currentMarketCategory = marketCategoryMapper.selectByPrimaryKey(1005000);
        catalogIndexVo.setCurrentCategory(currentMarketCategory);

        //默认的子分类组
        MarketCategoryExample marketCategoryExample1 = new MarketCategoryExample();
        MarketCategoryExample.Criteria criteria = marketCategoryExample1.createCriteria();
        criteria.andPidEqualTo(1005000);
        List<MarketCategory> marketCategories1 = marketCategoryMapper.selectByExample(marketCategoryExample1);
        catalogIndexVo.setCurrentSubCategory(marketCategories1);

        //3个list已经全部赋值好了，返回！
        return catalogIndexVo;
    }

    @Override
    public CatalogIndexVo queryCurrentCategory(Integer id) {
        //当前的父分类
        MarketCategory currentMarketCategory = marketCategoryMapper.selectByPrimaryKey(id);
        CatalogIndexVo catalogIndexVo = new CatalogIndexVo();
        catalogIndexVo.setCurrentCategory(currentMarketCategory);
        //当前的子分类组
        MarketCategoryExample marketCategoryExample = new MarketCategoryExample();
        MarketCategoryExample.Criteria criteria = marketCategoryExample.createCriteria();
        criteria.andPidEqualTo(id);
        List<MarketCategory> marketCategories = marketCategoryMapper.selectByExample(marketCategoryExample);
        catalogIndexVo.setCurrentSubCategory(marketCategories);
        return catalogIndexVo;
    }
}
